<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" class="w">
    <input type="checkbox" class="c">
    存储
    <script>
          var w = document.querySelector('.w')
               var c = document.querySelector('.c')
               console.log(c.checked);
               console.log(localStorage.getItem('uname'));
               
               
               
              if(localStorage.getItem('uname')){
                  w.value = localStorage.getItem('uname')
                  c.checked = true;
              }
              c.addEventListener('change',function(){
                  if(this.checked){
                    localStorage.setItem('uname',w.value)
                  }
              })
    </script>
</body>
</html>